package com.example.cloudmusicserve.controller;

import com.example.cloudmusicserve.entity.RecentPlay;
import com.example.cloudmusicserve.entity.ResMsg;
import com.example.cloudmusicserve.service.MusicSerivce;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @description: UserMusicController
 * @author: xiaoyuan
 * @time: 2023/5/29
 */
@RestController
@Api(tags = "用户音乐管理")
public class UserMusicController {

    //注入音乐服务
    @Resource
    MusicSerivce musicSerivce;
    //注入返回模板
    @Resource
    ResMsg resMsg;

    @ApiOperation("添加最近播放列表")
    @PostMapping("/addrecentplay")
    public ResMsg addUserRecentPlay(@RequestBody RecentPlay recentPlay){
        try{
            Integer integer = musicSerivce.addRecentPlay(recentPlay);
            resMsg.setCode(200);
            resMsg.setResmsg("添加成功");
            resMsg.setData(integer);
            return resMsg;

        }catch (Exception e){
            resMsg.setCode(400);
            resMsg.setResmsg("已存在");
            resMsg.setData("");
            return resMsg;

        }
    }


    @ApiOperation("获取最近播放列表")
    @PostMapping("/getuserrecentplay")
    public ResMsg queryByUsername(@RequestBody RecentPlay recentPlay){
        resMsg.setCode(200);
        resMsg.setResmsg("获取成功");
        resMsg.setData(musicSerivce.queryByUsername(recentPlay));
        return resMsg;
    }

}
